package top.truehaku.generator.common.util;

import org.springframework.util.ObjectUtils;

public class PackageUtils {

    public static String toPackage(String directory){
        if(ObjectUtils.isEmpty(directory)){
            return null;
        }
        directory = directory
                .replaceAll("^.+\\\\src\\\\main\\\\java\\\\", "")
                .replaceAll("\\\\", ".")
                .replaceAll("//","/")
                .replaceAll("^.+/src/main/java/", "")
                .replaceAll("/", ".");
        if (directory.endsWith(".")){
            directory = directory.substring(0,directory.length()-1);
        }
        return directory;
    }

    public static String toPath(String packageName){
        return packageName.replaceAll("\\.","/");
    }


    public static void main(String[] args) {
        String s = PackageUtils.toPath("xyz.iguilty.normal.common.annotation");
        System.out.println(s);
    }
}
